<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<!-- Mirrored from bos.asmhackers.net/docs/floppy/docs/detecting_floppy_drives.php.htm by HTTrack Website Copier/3.x [XR&CO'2013], Tue, 07 Oct 2014 11:24:00 GMT -->
<head>
<title>Bona Fide OSDev - Detecting Floppy Drives</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="osdev,os development, os design, operating system, tutorial, documents,  bochs, x86, intel, docs, system programming, programming, forum, chat">
<meta name="description" content="The place to go for OS Development related research. IRC Chat, Forum, Tutorials, Documents, & Downloads.">
<link href="../../../style.html" rel="stylesheet" type="text/css">
</head>

<body>

<table cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td colspan="2">
	 <table width="100%" cellpadding="0" cellspacing="0">
      <tr>
       <td><img src="../../../bflogo.html" alt="BonaFide OS Development"></td>
	<td>
</td>
<td>		<table style="border:1px dotted #000 ">
			<tr>
				<td>Welcome 193.10.194.145<br>Online Visitors: 3<br></td>
			</tr>
		</table> </td>
</tr>
</table>
</td>
</tr>
  <tr>
    <td colspan="2">
     <table width="100%" class="header">
      <tr>
       <td> <a href="http://bos.asmhackers.net/index.php" title="BF Home Page"> BF Home</a></td>
       <td><a href="http://www.2daylist.com/" onmouseover="this.href='http://bos.asmhackers.net/goal.php'" title="BF's Goal">The Goal </a></td>
       <td><a href="http://bos.asmhackers.net/help.php" title="How you can Help BF">How to Help </a></td>
       <td><a href="http://bos.asmhackers.net/contributors.php" title="Those that have donated to BF">Contributors</a></td>
       <td><a href="http://bos.asmhackers.net/contact.php" title="Email us">Contact BF </a></td>
      </tr>
      </table>
	</td>
  </tr>
  <tr>    <td valign="top" width="150">
	 <table width="150" cellpadding="0" cellspacing="3" class="menu">      <tr>
        <td> <a href="http://bos.asmhackers.net/tutorials.php?cat=0&amp;sort=1"><img src="../../../images/tuts.html" width="16" height="16" border="0" alt="[Tuts]"> Tutorials </a><br>
            <a href="http://bos.asmhackers.net/documents.php?cat=0&amp;sort=1"><img src="../../../images/docs.html" width="16" height="16" border="0" alt="[Docs]"> Documents </a><br>
            <a href="http://bos.asmhackers.net/downloads.php"><img src="../../../images/dl.html" width="16" height="16" border="0" alt="[DLs]"> Downloads </a><br>
            <a href="http://bos.asmhackers.net/chat.php"><img src="../../../images/chat.html" width="16" height="16" border="0" alt="[Chat]"> Chat </a><br>
            <!--<a href="/forums/"><img src="/images/forum.png" width="16" height="16" border="0" alt="[Forum]"> Forum </a><br>-->
            <a href="http://www.osdever.net/cottontail/" target="cottontail"><img src="../../../images/cottontail.html" width="16" height="16" border="0" alt="[Cottontail]"> Cottontail Archive </a><br>
            <a href="http://bos.asmhackers.net/books.php"><img src="../../../images/books.html" width="16" height="16" border="0" alt="[Books]"> Books </a><br>
            <a href="http://bos.asmhackers.net/links.php"><img src="../../../images/links.html" width="16" height="16" border="0" alt="[Links]"> Links </a><br>
            <a href="http://bos.asmhackers.net/search.php"><img src="../../../images/search.html" width="16" height="16" border="0" alt="[Search]"> Search </a><br>
        </td>
      </tr>
		 <center>
<script type="text/javascript"><!--
google_ad_client = "pub-5517142326360907";
google_alternate_color = "FFFFFF";
google_ad_width = 120;
google_ad_height = 240;
google_ad_format = "120x240_as";
google_ad_channel ="4707245488";
google_color_border = "CCCCCC";
google_color_bg = "FFFFFF";
google_color_link = "333333";
google_color_url = "003399.html";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="../../../../pagead2.googlesyndication.com/pagead/f.txt">
</script>
		 </center>     </table>
	</td>
    <td valign="top" width="90%">
     <table width="100%" height="100%" border="0" class="main" cellpadding="15">
      <tr>
       <td valign="top"><h1>Detecting Floppy Drives</h1>
<p>Floppy drives are all most always found on an x86 computer(at least for a few more years anyway, then they will likely dissappear). When it comes to making an OS, you are going to have to need some way of taking data off a floppy disk. That's rather easy if you can use BIOS interrupt 0x13, but you can't use BIOS interrupts in PMode. So you will need to write your own floppy driver. But to use a floppy driver, you will need to know what floppy drives exist on the system, if any. Fortunitly for us, the CMOS finds the floppy drives on bootup. We just have to get the data from the CMOS and decode it.</p>

<h2>Getting the Data From the CMOS</h2>
<p>To get the data from the CMOS, we must output the correct "index" to the data that we want to read to port 0x70. Once we have done that, we then read port 0x71, which will contain the data we requested. For finding floppy drive information, we need to use "index" 0x10:</p>

<pre class="code">
unsigned char c;
outportb(0x70, 0x10);
c = inportb(0x71);
</pre>

<p>Now that "c" contains the data, we just need to decode it!</p>

<h2>Decodding the Data</h2>
<p>Decodding the data we got from the CMOS is extremely easy. Before we do it though, we need to divide "c" into two parts. The high nibble contains info about the first floppy drive, and the low nibble contains info about the second floppy drive:</p>

<pre class="code">
a = c >> 4; // get the high nibble
b = c & 0xF; // get the low nibble by ANDing out the high nibble
</pre>

<p>Now, there are 5 official types of floppy drives that the most CMOSes can detect:</p>

<table border="0" cellpadding="2" cellspacing="1" align="center">
<tr><td>Type of drive:</td><td width="10"></td><td>Number the CMOS gives it:</td></tr>
<tr><td>360kb 5.25in</td><td width="10"></td><td>1</td></tr>
<tr><td>1.2mb 5.25in</td><td width="10"></td><td>2</td></tr>
<tr><td>720kb 3.5in</td><td width="10"></td><td>3</td></tr>
<tr><td>1.44mb 3.5in</td><td width="10"></td><td>4</td></tr>
<tr><td>2.88mb 3.5in</td><td width="10"></td><td>5</td></tr>
<tr><td>No drive</td><td width="10"></td><td>0</td></tr>
</table>

<p>So, to display what drive(s) are on the system, we can do this:</p>

<pre class="code">
char *drive_type[5] = { "no floppy drive", "360kb 5.25in floppy drive", "1.2mb 5.25in floppy drive", "720kb 3.5in", "1.44mb 3.5in", "2.88mb 3.5in"};
printf("Floppy drive A is an:\n");
printf(drive_type[a]);
printf("\nFloppy drive B is an:\n");
printf(drive_type[b]);
printf("\n");
</pre>

<p>The full source code for this tutorial may be downloaded <a href="http://osdev.neopages.net/downloads/tuts/detect_floppy_drives.zip">here</a>(you will have to supply your own inportb/outportb and printf functions).</p>
<br /><br /><p>This tutorial is Copyright &copy; 2002 by K.J.</p>
<h2>Rate this Article!</h2><br> <a href="http://bos.asmhackers.net/tutorials/detecting_floppy_drives.php?the_id=58&amp;rate=1&amp;incdec=1">Good</a> or <a href="http://bos.asmhackers.net/tutorials/detecting_floppy_drives.php&amp;rate=1&amp;incdec=0">Bad</a><div style="font-size:10px"><i>Viewed 1652 Times</i></div>       </td>
      </tr>
     </table>
   </td>
  </tr>
  <tr>
     <td colspan="2" class="credit">Intellectual Copyrights Reserved Bona Fide OS development 2001-2003. BFOSdev can take no responsibilty for the mishaps that may occur due to the content provided herein or for any other reasons. Use at your own risk
				<!-- BEGIN pStats! Tracking Code -->                                                                                        
				<script language="javascript"><!--                                                                                          
				document.write('<a target="_new" href="http://www.pstats.com/scripts/reports.asp?id=613"><img border=0 src="');             
				document.write('http://www.pstats.com/scripts/stats.asp?id=613&amp;loc=');                                                      
				document.write(escape(document.location));                                                                                  
				document.write('&ref=' + escape(document.referrer));                                                                        
				document.write('&res=' + screen.width + 'x' + screen.height);                                                               
				document.write('&type=graphic">');                                                                                          
				document.write('</a>');                                                                                                     
				// --></script>                                                                                                             
				<noscript><a href="http://www.pstats.com/"><img src="http://www.pstats.com/scripts/stats.asp?id=613" border=0></a></noscript>
				<!-- END pStats! Tracking Code --></td>
  </tr>
</table>
  </body>

<!-- Mirrored from bos.asmhackers.net/docs/floppy/docs/detecting_floppy_drives.php.htm by HTTrack Website Copier/3.x [XR&CO'2013], Tue, 07 Oct 2014 11:24:01 GMT -->
</html>
